<!DOCTYPE htm PUBLIC "-//W3C//DTD Xhtm 1.0 Transitional//EN" "DTD/xhtm1-transitional.dtd">
<htm xmlns="http://www.w3.org/1999/xhtm" xml:lang="de" lang="de">
<head>
 <meta http-equiv="content-type" content="text/htm; charset=iso-8859-1" />
 <meta http-equiv="content-style-type" content="text/css" />
 <meta name="author" content="Arlsair" />
 <meta name="date" content="2004-01-22" />
 <title>STMedianFilter</title>
 <link rel="stylesheet" type="text/css" href="../../style.css" />
</head><body>
<h1>STMedianFilter</h1>

<h2>&Uuml;bersicht</h2>
<b>Autor:</b> Tom Barry<br />
<b>Version:</b> 0.1.0.0<br />
<b>Download:</b> <a href="http://mywebpages.comcast.net/trbarry/downloads.htm" target="_blank">http://mywebpages.comcast.net/trbarry/downloads.htm</a><br />
<b>Kategorie:</b> R&auml;umlich-Zeitliche Weichzeichner<br />
<b>Anforderungen:</b>
<ul>
  <li>YV12 oder YUY2 Farbformat</li>
  <li>SSEMMX (=ISSE) f&auml;hige CPU</li>
</ul>

<hr size=2 width="100%" align=center>

<!-- #EndTemplate -->
<h2>Description</h2>
<p>STMedianFilter is a (slightly motion compensated) spatial/temporal median filter.<br>
<br>
It fairly very fine grained, using only adjacent pixels in space and time, so it
looks at the adjacent 26 locations to filter each location. It now filters both luma and chroma but chroma filtering is somewhat more limited, as described later.<br>
<br>
USAGE - To use it just:<br>
<br>
1) Place the STMedianFilter.dll in a directory somewhere. You can get it from www.trbarry.com/STMedianFilter.zip<br>
<br>
2) In your Avisynth file use commands similar to&nbsp;<br>
<br>
	LoadPlugin("F:\STMedianFilter\STMedianFilter.dll")<br>
	Avisource("D:\wherever\myfile.avi")<br>
	STMedianFilter(S_FilterThreshHold, S_EdgeThreshHold, T_FilterThreshHold, T_MotionThreshHold)&nbsp;<br>
<br>
Of course replace the file and directory names with your own and supply the integer
values for parameters.  Valid values for each are from 0 to 255.<br>
<br>
S and T above stand for spatial and temporal, respectively.<br>
<br>
A good starting point for parm values might be&nbsp;<br>
<br>
    STMedianFilter(8,15,4,7)<br>
<br>
Larger values cause more filtering but more artifacts. Parm descriptions:<br>
<br>
<b>  S_FilterThreshHold</b> - don't spatial filter pixel if it would change it more than this
Larger values may cause loss of fine line detail but it's not extremely sensitive.<br>
<br>
<b>  S_EdgeThreshHold</b> - don't spatial filter pixel if on an edge where vals change more    than this. It seems fairly forgiving, so it can be raised a lot if desired.<br>
<br>
<b>  T_FilterThreshHold</b> - don't Temporal filter pixel if it would change it more than this
Large values will cause ghosting. Don't set over 5-10 to avoid ghosting.<br>
<br>
<b>  T_MotionThreshHold</b> - don't Temporal filter pixel if uncompensated motion vals change more    than this. Don't set over about 10 to avoid ghosting.<br>
<br>
<br>
STMedianFilter should run on all SSEMMX machines or higher.&nbsp;</p>
<h2>Method of operation</h2>
<p>But if I understand it right a simple median filter is just a clipping step where a value is set to not extend past the high and low of its neighbors.&nbsp;<br>
<br>
For instance, if you had 3 pixels in a row that had the values &lt;5,8,7> you could clip the center one to not be outside the low of 5 or the high of 7,
so you would set it to 7.&nbsp;<br>
<br>
Now imagine you had a small 3x3 video screen, like one surface of a Rubiks cube. Imagine the previous frame was the bottom layer of the cube, the
current frame was the middle layer, and the next frame was the top.&nbsp;<br>
<br>
Then the current center pixel would be right in the center of the Rubics cube and there would be 13 ways you could draw a line through it and a pair
of two nearest neighbors.&nbsp;<br>
<br>
What I did was to compare each of those pairs of neighbors to see which pair was most agreeing on value. I used that pair to clip the value of the
center pixel.&nbsp;<br>
<br>
I also clipped the pixel value only if both:&nbsp;<br>
<br>
1) It would not change the pixel value by more then the FilterThreshold parm value, and&nbsp;<br>
<br>
2) The amount of 'uncompensated motion' (agreement on value by neighbors) was less than the MotionThreshHold parm value.
<br>
</p>
</body>
</html>
